import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class GameDraw extends Applet implements Runnable{
	
        Thread runner;
	int x = 115;
	int y = 115;
	int vx = 4;
	int vy = 2;
	
	public void init(){
		setBackground(Color.WHITE);
		setForeground(Color.RED);
	}
	
	public void paint(Graphics g){
            Graphics2D g2 = (Graphics2D) g;
            try{
                String fileName = "\\resources\\Boll_Bla.png";
                String workingDir = System.getProperty("user.dir");
                File file = new File(workingDir + fileName);
                
                Image ball_blue = ImageIO.read(file);
                BufferedImage buffed_ball_blue = (BufferedImage) ball_blue;
                
                g2.setColor(getBackground());
                g2.fillRect(0, 0, getWidth(), getHeight());
                
                g2.drawImage(buffed_ball_blue, x, y, null);
                
            }catch(IOException ex){}
        }
        
	public void run(){
		while(true){
			Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
			if(x > getWidth()){
				vx = -vx;
			}
			if(y > getHeight()){
				vy = -vy;
			}
			if(x < 1){
				vx = -vx;
			}
			if(y < 1){
				vy = -vy;
			}
			x += vx;
			y += vy;
			
			try {
				Thread.sleep(100);
			}catch(Exception e){}
			repaint();
		}
	}
        
	public void start(){
		if (runner == null){
			runner = new Thread(this);
			runner.start();
		}
   }

   public void stop(){
		if (runner != null){
         	runner.stop();
           	runner = null;
     	}
   }
}